

file_path = r"E:\test\密码临时导出\54807230-af36-43dd-a32d-bf7f105e2d58_Export-93c029d4-c074-44ad-973f-32301c8ab22f\密码 6139776ca6254e389ca896d4ece41ae0.md"

def read_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        return f.readlines()        
    return None

lines = read_file(file_path)

segment_num = 0
segs = {}

for line in lines:
    if line.startswith("###"):
        segment_num += 1
    segs[segment_num] = segs.get(segment_num, []) + [line]

#函数输入文件名称和文件内容，写入文件
def write_file(file_name, content):
    with open(file_name, 'w', encoding='utf-8') as f:
        f.writelines(content)

for k, v in segs.items():
    write_file(f"segment_{k}.md", v)
    

#读取文件行数
def read_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        return len(f.readlines())        
    return None

def process_type_1(lines):
    num=0
    for line in lines:
        if len(line.strip()) == 0:
            continue
        if line.startswith("#") or line.startswith("`"):
            continue
        line = line.replace('网址', '').replace('账号', '').replace('密码', '').replace(':', '')
        num += 1
        print(line.strip())
    print('-----------------------')
def process_type_2(lines):
    num=0
    for line in lines:
        if len(line.strip()) == 0:
            continue
        if line.startswith("`"):
            continue
        line = line.replace('网址', '').replace('账号', '').replace('密码', '').replace(':', '')
        if line.startswith("#"):
            line = line.replace('#', '')
        num += 1
        print(line.strip())
    print('-----------------------')

def process_type_3(lines):
    num=0
    for line in lines:
        if len(line.strip()) == 0:
            continue
        if line.startswith("`"):
            continue
        line = line.replace('网址', '').replace('账号', '').replace('密码', '').replace(':', '')
        if line.startswith("#"):
            line = line.replace('#', '')
        num += 1
        print(line.strip())
    print('-----------------------')
    
def process_type_4(lines):
    num=0
    for line in lines:
        if len(line.strip()) == 0:
            continue
        if line.startswith("`"):
            continue
        line = line.replace('网址', '').replace('账号', '').replace('密码', '').replace(':', '')
        if line.startswith("#"):
            line = line.replace('#', '')
        num += 1
        print(line.strip())
    print('-----------------------')
    

for k, v in segs.items():
    lines = read_file(f"segment_{k}.md")
    print(f"segment {k} has {lines} lines")
    if lines == 9:
        process_type_1(v)
    if lines == 7:
        process_type_2(v)
    if lines == 6:
        process_type_3(v)     
    if lines == 8:
        process_type_4(v)          